import sys


data = {} # {id: value}


def init(stu_number, stu_score):
    global data
    data = dict(zip(range(1, stu_number + 1), stu_score))
    # print(data)


def update(uid, value):
    global data
    data[uid] = value
    # print(data)

def query(uid_a, uid_b):
    return max(data.get(uid_a), data.get(uid_b))



def run():
    input_line_count = 0
    opt_count = 0
    stu_num = 0
    opt_num = 0

    for line in sys.stdin:
        a = line.split()
        if input_line_count == 0:
            stu_num = int(a[0])
            opt_count = int(a[1])
            input_line_count += 1
        elif input_line_count == 1:
            score_list = list(map(int, a))
            init(stu_num, score_list)
            input_line_count += 1
        else:
            opt = line.split()
            if opt[0] == 'Q':
                print(query(int(opt[1]), int(opt[2])))
            if opt[0] == 'U':
                update(int(opt[1]), int(opt[2]))
            # opt_num += 1
            # if opt_num == opt_count:
            #     break




if __name__ == "__main__":
    run()
